package com.zs.ktsms.service.impl;

import com.zs.ktsms.mapper.SupplierMapper;
import com.zs.ktsms.pojo.Address;
import com.zs.ktsms.pojo.Supplier;
import com.zs.ktsms.service.SupplierService;
import com.zs.ktsms.utils.Page;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/5/31 下午9:23
 */
@Service
public class SupplierServiceImpl implements SupplierService {

    @Resource
    private SupplierMapper supplierMapper;
    /**
     * 获取分页数据
     *
     * @param supName
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public Page<Supplier> getPage(String supName, Integer pageNo, Integer pageSize) {
        Page<Supplier> page = new Page<>();
        page.setPageSize(pageSize);
        page.setTotalCount(supplierMapper.count(supName));
        page.setPageNo(pageNo);
        int offset = (page.getPageNo()-1)*page.getPageSize();
        page.setData(supplierMapper.selectAll(supName,offset,page.getPageSize()));
        return page;
    }

    /**
     * 添加
     *
     * @param supplier
     * @return
     */
    @Override
    public int add(Supplier supplier) {
        return supplierMapper.add(supplier);
    }

    /**
     * 详情
     *
     * @param id
     * @return
     */
    @Override
    public Supplier detail(Integer id) {
        return supplierMapper.detail(id);
    }

    /**
     * 修改
     *
     * @param supplier
     * @return
     */
    @Override
    public int update(Supplier supplier) {
        return supplierMapper.update(supplier);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    public int delete(Integer id) {
        return supplierMapper.delete(id);
    }
}
